
*************************************************************************************************************
* Table B.6: Perceptions of the ePOS intervention
* This table reports summary statistics of households' and FPS dealers' stated preferences for and perceptions of the ePOS intervention in March

*************************************************************************************************************

****************************
*Household survey
*****************************

use "${SurveyDataDir}/JH_ePOS_HH_DataforAnalysis.dta",clear

*******************************************************************************
keep if ss_code == "SS01"

preserve 
tempfile HHdata_surveyedEL1
save `HHdata_surveyedEL1'
restore

*******************************************************************************
svyset [pw = pweight]


count if ghost_final == 1
scalar ghosts = r(N)
scalar obs = 3960   

*Get relative weights of AAY and PH rationcard holders by whether RC is in an urban area
sum pweight if rationcardtype == "AAY" & isurban == 0
scalar AAY_weight0 = r(sum)

sum pweight if rationcardtype == "PH" & isurban == 0
scalar PH_weight0 = r(sum)

sum pweight if rationcardtype == "AAY" & isurban == 1
scalar AAY_weight1 = r(sum)

sum pweight if rationcardtype == "PH" & isurban == 1
scalar PH_weight1 = r(sum)




*******************************************************************************
*  Summary of Preferences 
*******************************************************************************
*Recode values of e9_preference
gen e9_pref_1 = (e9_pref ==1) if !missing(e9_pref)
gen e9_pref_2 = (e9_pref ==2) if !missing(e9_pref)
gen e9_pref_3 = (e9_pref ==3) if !missing(e9_pref)
gen e9_pref_4 = (e9_pref ==4) if !missing(e9_pref)
gen e9_pref_5 = (e9_pref ==5) if !missing(e9_pref)

*create perceptions table and label
loc varlist "e9_pref_1 e9_pref_2 e9_pref_3 e9_pref_4 e9_pref_5 e10_why_prefer_manual_1 e10_why_prefer_manual_2 e10_why_prefer_manual_4 e10_why_prefer_manual_3 e10_why_prefer_manual_5 e10_why_prefer_manual__87 e11_why_prefer_epos_2 e11_why_prefer_epos_1 e11_why_prefer_epos_5 e11_why_prefer_epos_7 e11_why_prefer_epos_4 e11_why_prefer_epos_3 e11_why_prefer_epos_9 e11_why_prefer_epos_6 e11_why_prefer_epos_8 e11_why_prefer_epos__87"
perceptionTable `varlist'


*Overall preferences
label var e9_pref_1 "Strongly disagree" 
label var e9_pref_2 "Weakly disagree" 
label var e9_pref_3 "Weakly agree" 
label var e9_pref_4 "Strongly agree" 
label var e9_pref_5 "Did not know/answer"

*Variables for why people prefer manual interactions (out of those who prefer manual interactions)
label var e10_why_prefer_manual_1 "Manual transactions are faster"
label var e10_why_prefer_manual_2 "Manual transactions are easier to understand"
label var e10_why_prefer_manual_4 "Anyone can collect rations on my behalf"
label var e10_why_prefer_manual_3 "There are no problems with network or software"
label var e10_why_prefer_manual_5 "I can ask dealer to check and verify amounts purchased"
label var e10_why_prefer_manual__87 "Other"


*Variables for why people prefer ePOS (out of those who prefer ePOS)
label var e11_why_prefer_epos_2 "Lower chance of fraud by the FPS dealer"
label var e11_why_prefer_epos_1 "ePOS transactions faster"
label var e11_why_prefer_epos_5 "Only I can collect rations"
label var e11_why_prefer_epos_7 "I receive physical receipts"
label var e11_why_prefer_epos_4 "I know my exact entitlement and payment amounts"
label var e11_why_prefer_epos_3 "The official transaction is equal to what I receive"
label var e11_why_prefer_epos_9 "Dealer calls me to buy ration as he cannot hide supply"
label var e11_why_prefer_epos_6 "Benefits carry forward if I don't collect this month"
label var e11_why_prefer_epos_8 "I receive text message for transaction receipts"
label var e11_why_prefer_epos__87 "Other"

mat pTableHH =pTable
mat drop pTable

****************************
*Dealer survey
*****************************

use "${SurveyDataDir}/JHePOS_EL1_Dealer_data.dta",clear


tostring fps_uid, replace
drop if fps_uid == "."
merge 1:1 fps_uid using "${SurveyDataDir}/JHePOS_BL_Dealer_data.dta", keepusing(*_y0) nogen

tostring district_code, replace format("%02.0f")
tostring block_code, replace format("%03.0f")
tostring fps_code, replace format("%02.0f")


*Merge in Strata 
merge m:1 block_code using "${AdminDataDir}/blockLevel_strata.dta", keep(3) keepusing(strata)
drop _merge

qui distinct district_code block_code, j
assert `r(ndistinct)' == 132 


svyset [pw = pweight]


*Number of originally sampled FPS
scalar fps_obs = 396



*******************************************************************************
* Summary of Preference / Perceptions (Dealer)
*******************************************************************************

*create perceptions table and label
gen e17_pref_1 = (e17_pref ==1) if !missing(e17_pref)
gen e17_pref_2 = (e17_pref ==2) if !missing(e17_pref)
gen e17_pref_3 = (e17_pref ==3) if !missing(e17_pref)
gen e17_pref_4 = (e17_pref ==4) if !missing(e17_pref)
gen e17_pref_5 = (e17_pref ==5) if !missing(e17_pref)

loc varlist "e17_pref_1 e17_pref_2 e17_pref_3 e17_pref_4 e17_pref_5 e18_prefer_manual_1 e18_prefer_manual_7 e18_prefer_manual_2 e18_prefer_manual_4 e18_prefer_manual_3 e18_prefer_manual__87 e18_prefer_manual_6 e18_prefer_manual_5 e19_prefer_epos_2 e19_prefer_epos_1 e19_prefer_epos_4 e19_prefer_epos_3 e19_prefer_epos_5 e19_prefer_epos__87"

perceptionTable `varlist'


*Overall preference
label var e17_pref_1 "Strongly disagree" 
label var e17_pref_2 "Weakly disagree" 
label var e17_pref_3 "Weakly agree" 
label var e17_pref_4 "Strongly agree" 
label var e17_pref_5 "Did not know/answer"

*Variables for why people prefer manual interactions (out of those who prefer manual interactions)
label var e18_prefer_manual_1 "Manual transactions are faster"
label var e18_prefer_manual_2 "Manual transaction are easier to understand"
label var e18_prefer_manual_3 "I could give ration to people who deserved it but did not have ration cards"
label var e18_prefer_manual_4 "I could give to anyone in an beneficiary household, as well as relatives or neighbours"
label var e18_prefer_manual_5 "It is cheaper to run FPS operations"
label var e18_prefer_manual_6 "It is more profitable"
label var e18_prefer_manual_7 "There are no problems due to network or software"
label var e18_prefer_manual__87 "Other"


*Variables for why people prefer ePOS (out of those who prefer ePOS)
label var e19_prefer_epos_1 "ePOS transactions are faster"
label var e19_prefer_epos_2 "Beneficiaries can no longer accuse dealers of cheating, or there is a better relationship with beneficiaries"
label var e19_prefer_epos_3 "Beneficiaries are more informed"
label var e19_prefer_epos_4 "Nobody else can take away the ration in beneficiary's name now"
label var e19_prefer_epos_5 "The beneficiaryÕs balance ration carries forward to another month if they donÕt collect this month"
label var e19_prefer_epos__87 "Other"


**************
*Constructing the matrix 
**************

drop _all
svmat2 pTableHH, rnames(rown)
tempfile t
save `t'

drop _all
svmat2 pTable, rnames(rown)
replace rown = "e9_pref_1" if rown == "e17_pref_1"
replace rown = "e9_pref_2" if rown == "e17_pref_2"
replace rown = "e9_pref_3" if rown == "e17_pref_3"
replace rown = "e9_pref_4" if rown == "e17_pref_4"
replace rown = "e9_pref_5" if rown == "e17_pref_5"
replace rown = "e10_why_prefer_manual_1" if rown == "e18_prefer_manual_1"
replace rown = "e10_why_prefer_manual_2" if rown == "e18_prefer_manual_2"
replace rown = "e10_why_prefer_manual_3" if rown == "e18_prefer_manual_7"
replace rown = "e10_why_prefer_manual_4" if rown == "e18_prefer_manual_4"
replace rown = "e10_why_prefer_manual__87" if rown == "e18_prefer_manual__87"
replace rown = "e11_why_prefer_epos_1" if rown == "e19_prefer_epos_1"
replace rown = "e11_why_prefer_epos__87" if rown == "e19_prefer_epos__87"
replace rown = "e11_why_prefer_epos_6" if rown == "e19_prefer_epos_5"

merge 1:1 rown using `t', nogen
# delimit ;
loc rownameslist = "e9_pref_1 e9_pref_2 e9_pref_3 e9_pref_4 e9_pref_5 
e18_prefer_manual_5 e10_why_prefer_manual_1 e10_why_prefer_manual_2 e10_why_prefer_manual_3 e10_why_prefer_manual_4 
e18_prefer_manual_3 e10_why_prefer_manual_5  e18_prefer_manual_6 
e10_why_prefer_manual__87 
e11_why_prefer_epos_1 e11_why_prefer_epos_2 e11_why_prefer_epos_3 e11_why_prefer_epos_4 
e11_why_prefer_epos_5 e11_why_prefer_epos_6 e11_why_prefer_epos_7 e11_why_prefer_epos_8 
e11_why_prefer_epos_9 e19_prefer_epos_2 e19_prefer_epos_3 e19_prefer_epos_4 
e11_why_prefer_epos__87 ";
# delimit cr

cap drop ord
gen ord = 0

forval i =1/27{
loc r: word `i' of `rownameslist'
replace ord = `i' if rown == "`r'"
}

sort ord
drop ord

order(rown pTableHH1 pTableHH2 pTable1 pTable2)

mkmat pTableHH1 pTable1,  matrix(pTableComb) rownames(rown)

mat roweq pTableComb =  "Overall" "Overall" "Overall" "Overall" "Overall" "Manual" "Manual" "Manual" "Manual" "Manual" "Manual" "Manual" "Manual" "Manual" "ePOS" "ePOS" "ePOS" "ePOS" "ePOS" "ePOS" "ePOS" "ePOS" "ePOS" "ePOS""ePOS" "ePOS" "ePOS" 
loc N11 = pTableHH2[1]
loc N12 = pTable2[1]
loc N21 = pTableHH2[7]
loc N22 = pTable2[7]
loc N31 = pTableHH2[15]
loc N32 = pTable2[15]

loc str1 = "\emph{Overall, do you prefer ePOS to the old system of manual transactions?} & \textit{(N=`N11')}& \textit{(N=`N12')}"
loc str2 = "\emph{Reasons for preference of manual transactions:} & \textit{(N=`N21')} & \textit{(N=`N22')}"
loc str3 = "\emph{Reasons for preference of ePOS enabled transactions:} & \textit{(N=`N31')} & \textit{(N=`N32')}"


# delimit ;
esttab matrix(pTableComb, fmt(2)) using "${OutputDir}/TableB_6.tex",
	collabels( "Households" "Dealers") width(\hsize) 
	coeflabels(
	e9_pref_1 "\specialcell{Strongly disagree}"
	e9_pref_2 "\specialcell{Weakly disagree}"
	e9_pref_3 "\specialcell{Weakly agree}"
	e9_pref_4 "\specialcell{Strongly agree}"
	e9_pref_5 "\specialcell{Did not know/answer}"
	e10_why_prefer_manual_1 "\specialcell{Manual transactions faster}"
	e10_why_prefer_manual_2 "\specialcell{Manual transactions easier to understand}"
	e10_why_prefer_manual_3 "\specialcell{There are no problems with network or software}"
	e10_why_prefer_manual_4 "\specialcell{Anyone can collect rations on my behalf}"
	e10_why_prefer_manual_5 "\specialcell{Dealer to verify amounts purchased}"
	e10_why_prefer_manual__87 "\specialcell{Other}"
	e11_why_prefer_epos_1 "\specialcell{ePOS transactions are faster}"
    e11_why_prefer_epos_2 "\specialcell{There is a lower chance of fraud by the FPS dealer}"
    e11_why_prefer_epos_3 "\specialcell{The official transaction is equal to what I receive}"
    e11_why_prefer_epos_4 "\specialcell{I know my exact ration entitlement and payment amounts}"
    e11_why_prefer_epos_5 "\specialcell{Nobody else can collect ration in my name}"
    e11_why_prefer_epos_6 "\specialcell{Ration balance carry forward if I don't collect}"
    e11_why_prefer_epos_7 "\specialcell{I receive physical receipts after ePOS transactions}"
    e11_why_prefer_epos_8 "\specialcell{I receive text messages after ePOS transactions}"
    e11_why_prefer_epos_9 "\specialcell{The dealer calls me to buy ration as he cannot hide supply}"
    e11_why_prefer_epos__87 "\specialcell{Other}"
	e18_prefer_manual_3 "\specialcell{Could give ration to those who did not have ration cards}"
	e18_prefer_manual_6 "\specialcell{It is more profitable}"
	e18_prefer_manual_5 "\specialcell{It is cheaper to run FPS operations}"
	e19_prefer_epos_4 "\specialcell{Nobody can steal ration from beneficiary}"
	e19_prefer_epos_2 "\specialcell{Better relationship with beneficiaries}"
    e19_prefer_epos_3 "\specialcell{Beneficiaries are more informed}"
	)
	substitute(
		"            &  pTableComb&            \\" ""
		"\hline\hline" "\hline"
		".00\\" "\\"
		".&" "&"
		".00&" "&"
		".\\" "\\"
		"&           &" " & -- & "
		"&           \\" "& -- \\"
		"&         \\" "& -- \\"
		"&         &" " & -- & "
		"end{tabular*}"  "end{tabular}"
		)
	eqlabels(
		"`str1'"
		"`str2'"
		"`str3'", 
		prefix(\addlinespace[1mm] ) span
	)
	replace nolz
	prehead(\begin{tabular}{l*{3}{c}} \toprule);
#delimit cr
eststo clear

